package com.gsk.europepharma.salesReport.utils;

public class KeeStringUtils {

	public static String tabStrToString(String tab[]) {
		String returnValue = new String("");
		if (tab != null && tab.length != 0) {
			StringBuffer strBuf = new StringBuffer();
			boolean tour = false;
			for (int i = 0; i < tab.length; i++) {
				// ignore empty strings
				if (!"".equals(tab[i])) {
					if (tour == false) {
						strBuf.append('$').append(tab[i]);
						tour = true;
					} else {
						strBuf.append(tab[i]);
					}
					strBuf.append('$');
				}
			}
			returnValue = strBuf.toString();
		}

		return returnValue;
	}

	/**
	 * 
	 * @param str
	 * @return
	 */
	public static String[] stringToTabStr(String str) {
		String returnValues[] = new String[0];
		String param = str;
		if (param != null) {
			param = param.substring(1);
			int idx = param.lastIndexOf('$'); 
			param = param.substring(0,idx);
			returnValues = param.split("\\$");
		}
		return returnValues;
	}
	/**
	 * 
	 * @param str
	 * @return
	 */
	public static String keeStrReplace(String str) {
		String retStr = str; 
		if(retStr != null && !"".equals(retStr)) {
			retStr = retStr.substring(1);
			int idx = retStr.lastIndexOf('$'); 
			retStr = retStr.substring(0,idx);
			retStr = retStr.replaceAll("\\$",", ");
		} else {
			retStr = new String("");
		}
		return retStr;
	}
}
